<#assign pageName="新增用户信息">
<@override name="head-styles">
</@override>
<@override name="page-content">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>${pageName}</legend>
    </fieldset>
    <form class="layui-form padding-10" lay-filter="formUserAdd">
        <@ctrl.Hidden path="users.guid"/>
        <@ctrl.Textbox path="users.loginAccount" labelText="登录账号" required="required"/>
        <@ctrl.Textbox path="users.uname" labelText="用户名称" required="required"/>
        <@ctrl.Textbox path="users.pwd" labelText="账号密码" type="password" required="required"/>
        <@ctrl.Textbox path="users.pwdConfirm" labelText="密码确认" type="password" required="required"/>
        <@ctrl.TreeSelect path="users.depId" dataList=depList![] fieldText="depName" fieldValue="depId" labelText="所属机构" 
            fieldParentID="upperId" parentidValue="${(dep.upperId)!-1}" required="required"/>
        <@ctrl.CheckboxList path="users.roleId" options=roleList![] labelText="角色权限" textField="roleName" valueField="roleId" required="required" />
        <@ctrl.CheckboxList path="users.guid" options=guidList![] labelText="管理平台" textField="sysModuleName" valueField="guid"/>
        <@ctrl.FormAction/>
    </form>
</@override>
<@override name="page-scripts">
    <script>
        $(function(){
            layui.use(['form','layer', 'jquery'], function(){
                var form = layui.form;
                var layer=layui.layer;
                $=layui.jquery;
                //监听提交
                form.on('submit(submit)', function(data){
                    var checkedRole =[]; 
                    var checkedGuid =[]; 
                    $('input[name="roleId"]:checked').each(function(index, item){ 
                        checkedRole.push($(this).val()); 
                    });
                    $('input[name="guid"]:checked').each(function(index, item){ 
                        checkedGuid.push($(this).val()); 
                    });
                    data.field.roleId = checkedRole;
                    data.field.guid = checkedGuid;
                    submitData(data.field, '${contextPath}/admin/users/add', function(){location.href="${contextPath}/admin/users/management";});
                    return false;
                });
                //机构角色联动
                form.on('select(depId)', function(data){
                    var $this = $(this);
                    var guid = $('#guid').val();
                    var depId = data.value;
                    $.post('${rc.getContextPath()}/admin/roles/queryall', {'guid':guid,'depId':depId}, function(data){
                        var $html = "";
                        $.each(data, function(index, item){
                            $html += '<input type="checkbox" name="roleId"  title="'+item['roleName']+'" value="'+item['roleId']+'" lay-skin="primary">';
                        })
                        if($html==""){
                            $html= '<div style="color:red;line-height: 38px; font-weight: bold;">当前机构下暂无角色，请先到角色管理中添加！</div>';
                        }
                        $this.parents(".layui-form-item").next().find('.layui-input-block').html($html);
                        form.render();
                    })
                });
            })
       })
    </script>
</@override>
<@extends name="/layout/basepage.html"/> 
